package cn.agiledata.bank.barcodepayment.dao;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.hibernateBean.BarCodePayDetail;
import com.vnv.infrastructure.logic.IPBHibernate3BaseMgr;

public class BarCodePayDetailDaoImpl extends IPBHibernate3BaseMgr implements
		BarCodePayDetailDao {

	public void saveBarCodePayDetail(BarCodePayDetail detail) {
		getHibernateTemplate().save(detail);
		
	}

	public void updateBarCodePayDetail(BarCodePayDetail detail) {
		getHibernateTemplate().update(detail);
		
	}

	public BarCodePayDetail getBarCodePayDetailByPayFeeNo(String payFeeNo) {
		String hql = "from BarCodePayDetail t where t.payFeeNo = ?";
		return (BarCodePayDetail) getHibernateTemplate().find(hql, payFeeNo).get(0);
	}

    public BarCodePayDetail unLogHistoryDetail(String barCode) {
        String hql = "from BarCodePayDetail where barCode = ?";
        List resultList = getHibernateService().find(hql,barCode);
        return resultList.size()==0?null:(BarCodePayDetail) resultList.get(0);
    }

	
	public Set getBarCodePayDetailsBeforeNow(){
		
		String hql = "from BarCodePayDetail t where t.payFeeDate < ? and t.payfeeStatus = '"+Constant.USER_BARCODEPAY_STATUS_PAYED+"' and t.barCodePayTotal is null";
		List list = getHibernateTemplate().find(hql, new Date());
		Set set = new HashSet();
		set.addAll(list);
		return set;
	}

	public List getBarCodePayDetail(String barcode,String payfeeStatus) {
		String hql = "from BarCodePayDetail t where t.barCode = ? and  t.payfeeStatus = ?";
		Object[] obj = new Object[2];
		obj[0]=barcode;
		obj[1]= payfeeStatus;
		return getHibernateTemplate().find(hql,obj);
	}
	
}
